package com.aeoj.clientmanagement.domain.user.vo;

import com.aeoj.clientmanagement.domain.user.SysUser;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * author: ZSM
 * time: 2025-04-16 22:19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SysUserVO implements Serializable {
    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户账号
     */
    private String userName;

    /**
     * 用户昵称
     */
    private String nickName;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 手机号码
     */
    private String phonenumber;

    /**
     * 用户性别（0男 1女 2未知）
     */
    private String sex;

    /**
     * 头像地址
     */
    private String avatar;

    /**
     * 最后登录IP
     */
    private String loginIp;

    /**
     * 最后登录时间
     */
    private Date loginDate;

    /**
     * 备注
     */
    private String remark;

    /**
     * 将VO转换为实体对象
     */
    public SysUser toSysUser() {
        return SysUser.builder()
                .userId(this.userId)
                .userName(this.userName)
                .nickName(this.nickName)
                .email(this.email)
                .phonenumber(this.phonenumber)
                .sex(this.sex)
                .avatar(this.avatar)
                .loginIp(this.loginIp)
                .loginDate(this.loginDate)
                .remark(this.remark)
                .build();
    }

    /**
     * 将实体对象转换为VO
     */
    public static SysUserVO toSysUserVO(SysUser user) {
        if (user == null) {
            return null;
        }
        return SysUserVO.builder()
                .userId(user.getUserId())
                .userName(user.getUserName())
                .nickName(user.getNickName())
                .email(user.getEmail())
                .phonenumber(user.getPhonenumber())
                .sex(user.getSex())
                .avatar(user.getAvatar())
                .loginIp(user.getLoginIp())
                .loginDate(user.getLoginDate())
                .remark(user.getRemark())
                .build();
    }
}
